/******************************************************************************
Paper: The Impact of Welfare on Intergroup Relations
Author: Akshay Dixit

Survey: This .do file produces the following output:
		- Table 2 (Composition of Sample Households by State and Landownership Status)
		- Table 3 (Welfare Amount Received from All Programs in the Last 12 Months)
		- Figure S4 (Illustration of differences in land ownership by caste)
		- Table S11 (Comparison of households in lower and higher inequality villages)
		- Table S16 (Correlation between income and behavior towards outgroups)
		- Table S50 (Comparing landless households in Telangana and Andhra Pradesh)
		- Table S52 (Correlation between festival spending and sharing meals with other castes)
		
It also produces a number of descriptive stats reported in the main text, 
particularly in the section "The Impact of Welfare on Caste-based Social Integration."
******************************************************************************/

clear all
gl data "$identity/data/survey"

u "$data/Household Survey V2_clean.dta", clear

cd "$analysis"

******************************************************************************

*** Descriptive statistics ***

* Composition of Sample Households by State and Landownership Status

tab ownagriland state

* Welfare benefits for landed in Telangana

putexcel set "welfare_benefits.xlsx", replace 
putexcel B1 = "Telangana" C1 = "Andhra Pradesh"
putexcel A2 = "Own land" A3 = "Landless"

summ welfare_amount if telangana == 1 & ownagriland == 1
putexcel B2 = (r(mean)/83)
summ welfare_amount if telangana == 1 & ownagriland == 0
putexcel B3 = (r(mean)/83)
summ welfare_amount if telangana == 0 & ownagriland == 1
putexcel C2 = (r(mean)/83)
summ welfare_amount if telangana == 0 & ownagriland == 0
putexcel C3 = (r(mean)/83)

	
* RBS relative to annual income

	// RBS benefit
g rbs_benefit = welfare_amount - other_welfare

	// Annual income
g annual_income = q3p5
replace annual_income = . if annual_income < 0

summ rbs_benefit if rbs_benefit > 0, d
summ annual_income, d

	/*
		Full sample: Median RBS benefit (7,500) was 15% of the median annual income (50,000).
	*/


* Cross-border migration 

tab q1p8 
tab state if q1p8 < 7 & q1p8 > 0 

	/*
		The vast majority (82%) said they have always lived in the village.
		Only 9 households said that they had moved to the village in the last 6 years.
		5 of these 9 households were in Telangana, the other 4 in AP.
	*/
	
* Sample by caste category

tab q1p10

	/*
		Sample: 56% BC, 34% SC, 8% OC. 
		Of the remaining 2%, 1% were STs and the remaining 1% refused to share their caste identity.
	*/
	

* Landownership

summ land_area if ownagriland == 1, d

count if land_area < 5 & land_area != . & ownagriland == 1
count if land_area > 10 & land_area != . & ownagriland == 1
count if ownagriland == 1

	/*
		1516 landowners in the data, of whom 1206 (80%) own less than 5 acres.
		40 (3%) own more than 10 acres.
		Median is 2 acres.
	*/
	
* Landownership by caste category

tab q1p10, summ(land_area)
tab q1p10, summ(ownagriland)
	
	/*
		40% Scheduled Castes (SCs) own land.
		55% Backward Castes (BC) own land. 
		55% Other Castes (OC) own land. 
		
		 
		
	*/

* Token game: Comparing levels of sub-national trust in the two states

	// Andhra Pradesh
summ tokens_family_member if telangana == 0 & ownagriland == 1
di 10 - `r(mean)'
summ tokens_family_member if telangana == 0 & ownagriland == 0
di 10 - `r(mean)'
summ tokens_caste_member if telangana == 0 & ownagriland == 1
di 10 - `r(mean)'
summ tokens_caste_member if telangana == 0 & ownagriland == 0
di 10 - `r(mean)'

	// Telangana
summ tokens_family_member if telangana == 1 & ownagriland == 1
di 10 - `r(mean)'
summ tokens_family_member if telangana == 1 & ownagriland == 0
di 10 - `r(mean)'
summ tokens_caste_member if telangana == 1 & ownagriland == 1
di 10 - `r(mean)'
summ tokens_caste_member if telangana == 1 & ownagriland == 0
di 10 - `r(mean)'


* Number of castes in the data

bysort q1p10: distinct q1p11 if q1p11 != 98 & q1p11 != 99

	/* 	
		The 3,020 observations span 41 castes.
		This excludes "OTHERS, SPECIFY" (7% of sample) & "CASTE NOT SPECIFIED" (1.5% of sample).
	*/

*******************************************************************************

*** Comparing major castes *** 

g boya = (q1p11 == 301)
g kuruma = (q1p11 == 313)
g reddy = (q1p11 == 409)
g mala = (q1p11 == 114)
g madiga = (q1p11 == 112)

g major_caste = ""
replace major_caste = "Mala (SC)" if mala == 1
replace major_caste = "Madiga (SC)" if madiga == 1
replace major_caste = "Boya (BC)" if boya == 1
replace major_caste = "Kuruma (BC)" if kuruma == 1
replace major_caste = "Reddy (OC)" if reddy == 1

graph hbox land_area, over(major_caste) ytitle("Acres of land owned") noout
graph export "box_plot_major_caste.png", as(png) replace

*******************************************************************************

*** Correlation between reported income and caste attitudes/behavior ***

	/* 
		Controlling for education and hh_size: What is the correlation between income and intergroup behavior?
		Focus on the comparison state, AP.
	*/

* Income
list q4p4 q4p6 q4p9 annual_income if annual_income >= 1000000 & annual_income != .
replace annual_income = . if annual_income >= 1000000	

	/*
		There were four households for whom extremely high incomes were reported, in excess of Rs 1 million.
		Based on ownership of assets, these households are not that wealthy.
		These are probably data entry errors. Drop from the descriptive analysis.
	*/

qui reg donation annual_income education hh_size if telangana == 0 & scheduled_caste == 0, vce(cluster village)
outreg2 using "exploring_income_effect.tex", replace label nocons nor2 tex

foreach var in share_meal share_meal_others friends_same_caste {
	di "`var'"
	qui reg `var' annual_income education hh_size if telangana == 0, vce(cluster village)
	outreg2 using "exploring_income_effect.tex", append label nocons nor2 tex
}

cap erase "exploring_income_effect.txt"

*******************************************************************************

*** Comparing behavior and attitudes in low vs. high inequality areas in Andhra Pradesh ***

putexcel set "balance_check_inequality_hhsurvey_AP.xlsx", replace 
putexcel B1=("(1)") C1=("(2)") D1=("(3)") E1=("(4)") F1=("(5)") G1=("(6)")
putexcel C2=("Low inequality mean") D2=("High inequality mean") E2=("Difference") F2=("p-value") G2=("N")

local balance share_meal share_meal_others friends_same_caste caste_trust caste_neighbor caste_neighbor_others
local row = 3
local counter = 1

foreach var of local balance {
	
	di "`var'"
	
	sleep 2000
	local varlabel : var label `var'
	
		// Low inequality mean
	qui sum `var' if low_land_inequality == 1 & telangana == 0
	local low_mean = (r(mean))
	
		// High inequality mean
	qui sum `var' if low_land_inequality == 0 & telangana == 0
	local high_mean = (r(mean))
	
		// Regression
	qui reg `var' low_land_inequality if telangana == 0, vce(cluster village) 
	local p = 2*ttail(e(df_r), abs(_b[low_land_inequality]/_se[low_land_inequality]))
	local difference = _b[low_land_inequality]
	
		// Output
	putexcel A`row' = ("(`counter')")
	putexcel B`row' = ("`varlabel'")
	putexcel C`row' = (trim("`: display %10.2f `low_mean''"))
	putexcel D`row' = (trim("`: display %10.2f `high_mean''"))
	putexcel E`row' = ((_b[low_land_inequality]))
	putexcel F`row' = (`p')
	putexcel G`row' = (e(N))
	
	local ++row
	local ++counter
	
}

	// Donation outcome analyzed separately, because it is focused on non-SCs
qui sum donation if low_land_inequality == 1 & telangana == 0 & scheduled_caste == 0
local low_mean = (r(mean))

qui sum donation if low_land_inequality == 0 & telangana == 0 & scheduled_caste == 0
local high_mean = (r(mean))

qui reg donation low_land_inequality if telangana == 0 & scheduled_caste == 0, vce(cluster village)
local p = 2*ttail(e(df_r), abs(_b[low_land_inequality]/_se[low_land_inequality]))
local difference = _b[low_land_inequality]

putexcel A9 = ("(7)")
putexcel B9 = ("Donation (Indian Rupees)")
putexcel C9 = (trim("`: display %10.2f `low_mean''"))
putexcel D9 = (trim("`: display %10.2f `high_mean''"))
putexcel E9 = ((_b[low_land_inequality]))
putexcel F9 = (`p')
putexcel G9 = (e(N))

*******************************************************************************

*** Means of outcomes for landless sample in both states ***

putexcel set "balance_check_landless.xlsx", replace 
putexcel B1=("(1)") C1=("(2)") D1=("(3)") E1=("(4)") F1=("(5)")
putexcel C2=("Landless TS") D2=("Sample size") E2=("Landless AP") F2=("Sample size")

local balance share_meal share_meal_others friends_same_caste caste_trust caste_neighbor caste_neighbor_others
local row = 3
local counter = 1

foreach var of local balance {
	
	di "`var'"
	
	sleep 2000
	local varlabel : var label `var'
	
		// Landless mean in TS
	qui sum `var' if ownagriland == 0 & telangana == 1
	local ts_mean = (r(mean))
	local ts_num = (r(N))
	
		// Landless mean in AP
	qui sum `var' if ownagriland == 0 & telangana == 0
	local ap_mean = (r(mean))
	local ap_num = (r(N))
	
		// Output
	putexcel A`row' = ("(`counter')")
	putexcel B`row' = ("`varlabel'")
	putexcel C`row' = (trim("`: display %10.2f `ts_mean''"))
	putexcel D`row' = ("`ts_num'")
	putexcel E`row' = (trim("`: display %10.2f `ap_mean''"))
	putexcel F`row' = ("`ap_num'")
	
	local ++row
	local ++counter
	
}

	// Donation: Landless mean in TS
qui sum donation if ownagriland == 0 & telangana == 1 & scheduled_caste == 0
local ts_mean = (r(mean))
local ts_num = (r(N))

	// Donation: Landless mean in AP
qui sum donation if ownagriland == 0 & telangana == 0 & scheduled_caste == 0
local ap_mean = (r(mean))
local ap_num = (r(N))

putexcel A9 = ("(7)")
putexcel B9 = ("Donation (Indian Rupees)")
putexcel C9 = (trim("`: display %10.2f `ts_mean''"))
putexcel D9 = ("`ts_num'")
putexcel E9 = (trim("`: display %10.2f `ap_mean''"))
putexcel F9 = ("`ap_num'")

*******************************************************************************

*** Correlation between inter-caste interaction and festival spending ***

cap erase "share_meal_festival.tex"

reg share_meal adj_festival_spending, vce(cluster village)
outreg2 using "share_meal_festival.tex", append label nocons nor2

reg share_meal adj_festival_spending ownagriland i.education i.q1p10, vce(cluster village)
outreg2 using "share_meal_festival.tex", append label nocons nor2

cap erase "share_meal_festival.txt"

*******************************************************************************

clear


